<%--
  Created by IntelliJ IDEA.
  User: 兰宦君
  Date: 2015/10/9
  Time: 8:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
<head>
  <title>后台管理系统———职工管理</title>
  <%@ include file="../../layout/import.jsp"%>
  <script type="text/javascript">
    function delEmployee(employeeid) {
      if(confirm("确定删除吗？删除后不可恢复！")){
        $.ajax({
          url: "/admin/delEmployee.do",
          data: {id:employeeid},
          method: "POST",
          dataType: "json",
          error: function () {
            alert("表单提交出错，请稍后再试");
          },
          success: function(response) {
            if(response.code == 0) {
              alert("删除成功");
              window.location.href = "/admin/employee.do";

            }
            else {
              alert(response.description);
            }
          }
        });
      }
    }
  </script>
</head>
<body>
<%@ include file="nav.jsp"%>

<div class="container" style="min-height: 72%">
  <div class="col-sm-12">
    <a class="btn btn-primary" href="/admin/newEmployee.do">新职员</a>
    <br /><br />
    <table class="table table-hover">
      <tr>
        <th>职工名</th><th>性别</th><th>邮箱</th><th>电话号码</th><th>职务</th><th>操作</th>
      </tr>

      <c:forEach var="employee" items="${employeeList}">
        <tr>
          <td>${employee.username}</td>
          <td>${employee.gender}</td>
          <td>${employee.email}</td>
          <td>${employee.phone}</td>
          <td>${employee.role}</td>
          <td>
            <a href="/admin/employeeEdit.do?id=${employee.id}">编辑</a>
            <a onclick="delEmployee(${employee.id})">删除</a>
          </td>
        </tr>
      </c:forEach>

    </table>

  </div>

</div>


<%@ include file="../footer.jsp"%>
</body>
</html>